#include "gofgame/dungeonkeeper/AppDelegate.h"
#include "gofgame/dungeonkeeper/MainScene.h"
#include "gofgame/common/Ref.h"
#include "gofgame/common/new.h"
#include "gofgame/dungeonkeeper/game/LevelScene.h"
#include "gofgame/dungeonkeeper/game/GameManager.h"
#include "gofgame/dungeonkeeper/menuscene/MenuScene.h"
using namespace gofgame::dungeonkeeper;
using namespace gofgame::dungeonkeeper::game;

#include "cocos2d.h"
#include "CCEGLView.h"
#include "AppDelegate.h"
#include "SimpleAudioEngine.h"
#include "gofgame/common/resource/Resource.h"

using namespace CocosDenshion;
using namespace cocos2d;
using namespace gofgame::common;
using namespace gofgame::common::resource;
using namespace gofgame::dungeonkeeper::menuscene;

AppDelegate::AppDelegate() {
}

AppDelegate::~AppDelegate() {
    SimpleAudioEngine::end();
}

bool AppDelegate::applicationDidFinishLaunching() {
    CCDirector *director = CCDirector::sharedDirector();
    director->setOpenGLView(CCEGLView::sharedOpenGLView());
	CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1024,768,kResolutionShowAll);
    director->setDisplayStats(true);
    director->setAnimationInterval(1.0 / 60);

	Resource::loadAll();
	MenuScene *ms = MenuScene::create();
	try {
		director->runWithScene(ms);
	} catch (Exception &ex) {
		CCMessageBox(ex.getMessage(), "Error");
	}
    return true;
}

void AppDelegate::applicationDidEnterBackground() {
    CCDirector::sharedDirector()->stopAnimation();
    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

void AppDelegate::applicationWillEnterForeground() {
    CCDirector::sharedDirector()->startAnimation();
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
